package cn.lqz.bucttrain.controller;

import cn.lqz.bucttrain.annotations.PageQueryAutoFill;
import cn.lqz.bucttrain.pojo.dto.TrainCreateOrUpdateDTO;
import cn.lqz.bucttrain.pojo.dto.TrainPageQueryDTO;
import cn.lqz.bucttrain.pojo.entity.Train;
import cn.lqz.bucttrain.pojo.vo.OrderVO;
import cn.lqz.bucttrain.pojo.vo.PageResultVO;
import cn.lqz.bucttrain.pojo.vo.ResponseVO;
import cn.lqz.bucttrain.service.TrainService;
import cn.lqz.bucttrain.utils.ResponseUtils;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 列车controller
 */
@RestController
@RequestMapping("/train")
@Validated
public class TrainController {
    @Resource
    private TrainService trainService;

    /**
     * 获取数据
     * @param trainPageQueryDTO
     * @return
     */
    @PostMapping("/loadTrainList")
    @PageQueryAutoFill
    public ResponseVO<PageResultVO> loadTrainList(TrainPageQueryDTO trainPageQueryDTO) {
        return ResponseUtils.success(trainService.loadTrainList(trainPageQueryDTO));
    }

    /**
     * 删除
     * @param trainId
     * @return
     */
    @PostMapping("/deleteTrain")
    public ResponseVO deleteTrain(@NotNull Long trainId){
        trainService.deleteTrain(trainId);
        return ResponseUtils.success();
    }

    /**
     * 添加或修改
     * @param trainCreateOrUpdateDTO
     * @return
     */
    @PostMapping("/addOrUpdateTrain")
    public ResponseVO addOrUpdateTrain(@Valid TrainCreateOrUpdateDTO trainCreateOrUpdateDTO){
        trainService.addOrUpdateTrain(trainCreateOrUpdateDTO);
        return ResponseUtils.success();
    }

    /**
     * 导出列车excel表
     * @param trainList
     * @param response
     */
    @PostMapping("/exportTrainExcel")
    public void exportOrderExcel(@RequestBody List<Train> trainList, HttpServletResponse response){
        trainService.exportOrderExcel(trainList,response);
    }

}
